package star.core.util.geometry;



public class FloatXYZ implements Comparable<FloatXYZ> {
	public float x = 0;
	public float y = 0;
	public float z = 0;
	private int axis;
	
	
	public void setInf(FloatXYZ point)
	{
		this.x=set_min(this.x,point.x);
		this.y=set_min(this.y,point.y);
		this.z=set_min(this.z,point.z);
	}
	
	private float set_min(float x,float y)
	{
		if(x>y)
			return y;
		
		return x;
	}
	
	
	private float set_max(float x,float y)
	{
		if(x<y)
			return y;
		return x;
	}
	
	public void setSup(FloatXYZ point)
	{
		this.x=set_max(this.x,point.x);
		this.y=set_max(this.y,point.y);
		this.z=set_max(this.z,point.z);
	}
	
	public void setDivide(float num)
	{

		this.x=this.x/num;
		this.y=this.y/num;
		this.z=this.z/num;
	}
	
	public void sumPoint(FloatXYZ p)
	{
		this.x+=p.x;
		this.y+=p.y;
		this.z+=p.z;
	}

	
	public FloatXYZ setProduct(float num)
	{
		FloatXYZ npoint= new FloatXYZ();
		npoint.x=this.x*num;
		npoint.y=this.y*num;
		npoint.z=this.z*num;
		return npoint;
	}
	
	public float getElement(int index)
	{
		if(index==0)
			return this.x;
		else if(index==1)
			return this.y;
		else if(index==2)
			return this.z;
		else
			return 0;
	}
	
	public FloatXYZ setSum(FloatXYZ point)
	{
		FloatXYZ npoint= new FloatXYZ();
		npoint.x=(this.x + point.x)==0 ? (float)-8.88178e-016:(this.x + point.x);
		npoint.y=(this.y + point.y)==0 ? (float)-8.88178e-016:(this.y + point.y);
		npoint.z=(this.z + point.z)==0 ? (float)-1.11022e-016:(this.z + point.z);
		return npoint;
	}
	
	public FloatXYZ setMinusPoint(FloatXYZ point)
	{
		FloatXYZ npoint= new FloatXYZ();
		npoint.x=this.x - point.x;
		npoint.y=this.y - point.y;
		npoint.z=this.z - point.z;
		return npoint;
	}
	
	public float[] setMinus(FloatXYZ point)
	{
		float vector[] = {0,0,0};
		vector[0]=this.x-point.x;
		vector[1]=this.y-point.y;
		vector[2]=this.z-point.z;
		return vector;
	}
	
	public float[] getVector()
	{
		float[] vector = new float[3];
		vector[2]=this.z;
		return vector;
	}
	
	public float dot(float[] norm)
	{
		return this.x*norm[0] + this.y*norm[1] + this.z*norm[2];
	}
	
	public String toString() {
		return "[" + x + ", " + y + ", " + z + "]";
	}

	/**
	 * metodo compare per il confronto tra i due 
	 * array di punti che vengono creati durante il
	 * controllo dell'intersezione nella gerarchia Aabb
	 */
	public int compareTo(FloatXYZ f) {
	    final int BEFORE = -1;
	    final int EQUAL = 0;
	    final int AFTER = 1;
	    if(this.getElement(this.axis)<f.getElement(f.axis))
	    return BEFORE;
	    else if(this.getElement(this.axis)>f.getElement(f.axis))
	    	return AFTER;
	    else
	    	return EQUAL;
	}
	
	public void setAxis(int axis)
	{
		this.axis=axis;
	}

}
